<template>
	<el-dialog title="" visible :show-close="false" :modal-append-to-body="false" class="wrap" size="tiny">
		 <div class="bt">物品退费</div>
		<i class="el-icon-close close" @click="cancel" style="color: white;"></i>
		<el-form label-width="100px" class="form">
			<el-form-item label="学生名称">
				  <el-input v-model="form.zwm"  icon="info" class="select-block"></el-input>
			</el-form-item>
			<el-form-item label="可退数量">
                <el-input v-model="form.cns" :readonly="true" class="select-block"></el-input>
            </el-form-item>
			<!--<el-form-item label="总价">
                <el-input v-model="form.jg" :readonly="true" class="select-block"></el-input>
            </el-form-item>
            <el-form-item label="单价">
                <el-input v-model="form.jcjg" :readonly="true" class="select-block"></el-input>
            </el-form-item>-->
             <el-form-item label="可退金额">
                <el-input v-model="form.je" :readonly="true" class="select-block"></el-input>
            </el-form-item>
            <el-form-item label="退费数量">
				  <el-input v-model="jzks" type="number"  class="select-block"></el-input>
			</el-form-item>
			<el-form-item label="退费金额">
				  <el-input v-model="tfje" type="number"  class="select-block"></el-input>
			</el-form-item>
			<el-form-item label="退费原因">
				  <el-input v-model="form.tfyy" type="textarea"  :rows="4"   icon="info" class="select-block"></el-input>
			</el-form-item>

		</el-form>
		<el-button type="primary" class="submit" @click="loadinfo">确定</el-button>
		<el-button type="danger" class="submit" @click="cancel">退出</el-button>
	</el-dialog>
</template>

<script type="text/javascript">
	import qs from 'qs'
	export default {
		props: ['params'],
		data() {
			return {
				form: {
					zwm:'',
					jg:'',
					jcjg:'',
					tfyy:'',
					jzks:'',
					cns:'',
					xsid:'',
					xsksid:'',
					ordermxid:'',
				},
				tfje:'',
				jzks:'',
			}
		},
		created() {
			console.log(this.params,'dfdfdfdfdfdf')
			if(this.params.row){
				this.form.zwm=this.params.row.zwm;
	           this.form.cns=this.params.row.cns;
	           this.form.jg=this.params.row.jg;
	           this.form.jcjg=this.params.row.jcjg+'';
	           this.form.xsid=this.params.row.xsid;
	           this.form.ordermxid=this.params.row.ordermxid;
	           this.form.xsksid=this.params.row.spid;
	           this.form.je=this.params.row.je;
			}else{
				this.form.zwm=this.params.zwm;
	           this.form.cns=this.params.cns;
	           this.form.jg=this.params.jg;
	           this.form.jcjg=this.params.jcjg+'';
	           this.form.xsid=this.params.xsid;
	           this.form.ordermxid=this.params.ordermxid;
	           this.form.xsksid=this.params.spid;
	            this.form.je=this.params.je;
			}
		},
				 watch:{
            'tfje': function(newVal,oldVal){
                if(parseInt(newVal) > parseInt(this.form.jg)) {//如果小于等于零
					this.tfje = 0.00
                     this.$message.warning('输入的退费金额不能超过总价!')
                }
            },
            'jzks': function(newVal,oldVal){
                if(parseInt(newVal) > parseInt(this.form.cns)) {//如果小于等于零
					this.jzks = 0
                     this.$message.warning('输入的退货数量不能超过可退数量!')
                }
            }
        },
		methods: {
			loadinfo(){
				if(!this.jzks) {
					this.$message.warning('请填写退费数量');
					this.$store.state.loading = false;
					return;
				}
				else if(!this.tfje) {
					this.$message.warning('请填写退费金额');
					this.$store.state.loading = false;
					return;
				}
				 var logininfo = JSON.parse(localStorage.logininfo) ;
				 var params3 = qs.stringify({
                             yhid:logininfo.id,
							 xxid:logininfo.xxid,
							 xsid:this.form.xsid,
							 tfje:this.tfje,
							 tfyy:this.form.tfyy,
							 ordermxid:this.form.ordermxid,
							 jzks:this.jzks,
							 xsksid:this.form.xsksid,

						});
				 this.axios.post(this.$store.state.api+'xstf/wptfinsert',params3)
				 .then( res =>  {
						if(res.data.code == 1) {
							this.$emit('close', { type: 'edit', cancel: false });
							this.$message.success(res.data.msg);
							this.$store.state.loading = false;
						} else {
						    this.$message.warning(res.data.msg);
							this.$store.state.loading = false;
						}
					 }).catch(res => {
						 this.$message.danger("服务器异常");
			 				this.$store.state.loading = false;
					 })
			},
			cancel() {
				this.$emit('close', { type: 'edit', cancel: true })
			},
			},
	}
</script>

<style lang="less" scoped>
	.wrap {
		text-align: center;
	}
	.bt{
			position: absolute;
			width: 100%;
			height: 50px;
			margin: 0 auto;
			top:0;
			left:0;
			background: #50BFFF;
			margin-bottom: 20px;
			color:white;
			text-align:left;
			line-height: 50px;
			font-size: 17px;
			padding-left: 15px;
		}
	.form {
		text-align: left;
		margin-top: 15px;
	}
	.select-block {
		display: block;
	}

	.submit {
		width: 120px;
	}
</style>
